package com.iflytek.ci.qams.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.iflytek.ci.cpms.domain.Milestone;
import com.iflytek.ci.cums.domain.Account;
import com.iflytek.ci.main.domain.Attachment;
import com.iflytek.ci.qams.domain.Issue;
import com.iflytek.ci.qams.domain.IssueInformation;
import com.iflytek.ci.qams.domain.SelectCondition;
import com.iflytek.ci.qams.dto.IssueMilestone;
import com.iflytek.framework.mybatis.extra.MyBatisDao;
import com.iflytek.framework.pagination.PaginationCriteria;
import com.iflytek.framework.pagination.PaginationResult;

/**
 * <p>
 * the interface of issuemain's database visit
 * </p>
 * Created with IntelliJ IDEA. User: liyasoft Date: 12-11-2 Time: 下午4:42
 */
@MyBatisDao
public interface IssueDao {

	/**
	 * According to the state to obtain the corresponding feedback problem list.
	 * 
	 * @param status_map
	 *            state parameter
	 * @param criteria
	 *            pagination parameter
	 * @return feedback problem list.
	 */
	PaginationResult<Issue> issues_page_with_status(
			Map<String, Object> status_map, PaginationCriteria criteria);

	/**
	 * Paging access all of the feedback list.
	 * 
	 * @param criteria
	 *            paging parameters.
	 * @return feedback list.
	 */
	PaginationResult<Issue> pageIssue(PaginationCriteria criteria);

	/**
	 * Search the issuemains' information that match the condition and paging
	 * them
	 * 
	 * @param criteria
	 *            paging information
	 * @param params
	 *            Map<String,Object> the query condition The map's key: id:
	 *            issuemain's id issuetype:issuemain's type issuelabel:
	 *            issuemain's label(state) p_id: related project's id summary:
	 *            the summary of the issue
	 * @return Paging information and the issues' information that match the
	 *         query coondition
	 */
	PaginationResult<Issue> pageFindIssue(PaginationCriteria criteria,
			Map<String, Object> params);

	/**
	 * For a project under the specified state feedback problem list.
	 * 
	 * @param project
	 *            project pk number.
	 * @param status_map
	 *            state parameter.
	 * @param criteria
	 *            paging parameters.
	 * @return feedback list.
	 */
	PaginationResult<Issue> issues_with_project(long project,
			Map<String, Object> status_map, PaginationCriteria criteria);

	/**
	 * Based on the primary key to access to information.
	 * 
	 * @param id
	 *            primary key.
	 * @return information.
	 */
	Issue issue_with_id(long id);

	/**
	 * According to the problem of acquiring information marker.
	 * 
	 * @param key
	 *            project key.
	 * @return information.
	 */
	IssueInformation issue_with_key(String key);

	/**
	 * According to the problem of acquiring information marker.
	 * 
	 * @param key
	 *            project key.
	 * @return information.
	 */
	List<Attachment> attachments_with_key(String key);

	/**
	 * Create a feedback problem.
	 * 
	 * @param issue
	 *            The problem of information.
	 * @return return equal to or greater than 0 created successfully.
	 */
	int new_issue(Issue issue);

	/**
	 * Update information.
	 * 
	 * @param issue
	 *            The problem of information.
	 * @return return equal to or greater than 0 update successfully.
	 */
	int update_issue(Issue issue);

	/**
	 * Update number of responses.
	 * 
	 * @param issue_id
	 *            issue pk number.
	 * @param comment_size
	 *            the comments size.
	 * @return return equal to or greater than 0 update successfully.
	 */
	int update_issue_comment_size(long issue_id, long comment_size);

	/**
	 * Update status label.
	 * 
	 * @param issue_ids
	 *            issue pk number. one or more.
	 * @param label
	 *            status label.
	 * @return return equal to or greater than 0 update successfully.
	 */
	int update_issue_label(String[] issue_ids, int label);

	/**
	 * Be assigned to someone.
	 * 
	 * @param issue_id
	 *            issue pk number.
	 * @param assign_account
	 *            assign account id.
	 * @return If the return is greater than or equal to 0 assignment success.
	 */
	int update_issue_assign(long issue_id, long assign_account);

	/**
	 * delete one or more feedback.
	 * 
	 * @param issue_ids
	 *            issue pk number. one or more.
	 * @return If the return is greater than or equal to 0 delete success.
	 */
	int remove_issues(long[] issue_ids);

	/**
	 * 跟新问题的回复数量
	 * 
	 * @param size
	 *            回复数量
	 * @param id
	 *            问题ID
	 */
	int issue_comment_size(int size, long id);

	/**
	 * select top1 from issue by pid
	 * 
	 * @param pid
	 * @return issue
	 */
	Issue getTop(long pid);

	/**
	 * update time when issue closed
	 * 
	 * @param date
	 *            closed date
	 * @param ids
	 *            update issue_ids
	 */
	int update_updateTime(String[] ids, Date date);

	/**
	 * update assignee when issue assigneed
	 * 
	 * @param uname
	 *            assigneed user
	 * @param ids
	 *            update issue_ids
	 */
	int update_assignee(String[] ids, String uname);

	/**
	 * get team_account by issue_id
	 * 
	 * @param ids
	 * @return uinfo
	 */
	List<Account> uinfo(String ids);

	/**
	 * get opend_issue_count by login_name
	 * 
	 * @param login
	 * @return int count
	 */
	int get_count_assignee(String login);

	/**
	 * set priopity by issue_ids
	 * 
	 * @param ids
	 */
	int set_priopity(String[] ids, int priopity);

	/**
	 * get issues by login_name
	 * 
	 * @param criteria
	 *            , login
	 * @return issues
	 */
	PaginationResult<Issue> page_getIssueByLogin(PaginationCriteria criteria,
			String login, String name);

	/**
	 * get issues by leader
	 * 
	 * @param criteria
	 *            ,login
	 * @return issues
	 */
	PaginationResult<Issue> page_getIssueByLeader(PaginationCriteria criteria,
			String leader, String name);

	/**
	 * get issue by login and status
	 * 
	 * @param criteria
	 * @param login
	 * @param params
	 * @return
	 */
	PaginationResult<Issue> page_issue_login_status(
			PaginationCriteria criteria, String login, String name,
			Map<String, Object> params);

	/**
	 * get issue by leader
	 * 
	 * @param criteria
	 * @param login
	 * @param name
	 * @param params
	 * @return
	 */
	PaginationResult<Issue> page_issue_leader_status(
			PaginationCriteria criteria, String login, String name,
			Map<String, Object> params);

	/**
	 * get count reported issue by login
	 * 
	 * @param login
	 * @return count
	 */
	int get_number_reporte(String login);

	/**
	 * get issue by login with 10 and order by priopity,creater
	 * 
	 * @param login
	 * @return issue
	 */
	List<Issue> issue_assignee_order(String login);

	/**
	 * get issue by reporter with 10 and order by priopity,creater
	 * 
	 * @param login
	 * @return
	 */
	List<Issue> issue_reporter_order(String login);

	/**
	 * get number of undo issue by leader
	 * 
	 * @param login
	 * @return number of issue undo
	 */
	int get_count_leader_todo(String login);

	/**
	 * get number of all undo issue
	 * 
	 * @return number of issue undo
	 */
	int get_count_admin_todo();

	/**
	 * get all issue by status
	 * 
	 * @return issue
	 */
	List<Issue> get_issue_order();

	/**
	 * get leader's assigneeIssue and issue be responsible for
	 * 
	 * @param leader
	 *            's loginName
	 * @return issue
	 */
	List<Issue> get_issue_leader_order(String login);

	/**
	 * get issue_assignne with status
	 * 
	 * @param login
	 *            ,status
	 * @return issue
	 */
	PaginationResult<Issue> page_assignee_status(String login, String label,
			PaginationCriteria criteria);

	/**
	 * 通过ids 获取相关的该反馈信息
	 * 
	 * @param ids
	 * @return issue
	 */
	List<Issue> get_issues_by_ids(String[] ids);

	/**
	 * 获取该用户提出的反馈信息
	 * 
	 * @param criteria
	 * @param login
	 * @param label
	 * @return
	 */
	PaginationResult<Issue> page_reporte_status(PaginationCriteria criteria,
			String login);

	/**
	 * 关闭问题
	 * 
	 * @param ids
	 * @param status
	 *            0为打开操作，1为关闭操作
	 */
	int close_or_open_issues(String[] ids, int status);

	/**
	 * get number of issues about someone milestone with one condition
	 * 
	 * @param milestone_id
	 * @param map
	 *            (name value)
	 * @return issue number
	 */
	int issue_number_with_milestone_param(long milestone_id, Map map);

	/**
	 * get all issues with milestone_id
	 * 
	 * @param milestone_id
	 * @return
	 */
	List<Issue> issues_with_milestone(long milestone_id);

	/**
	 * update issue_milestone
	 * 
	 * @param map
	 */
	int update_issue_milestone(Map<String, Object> map);

	/**
	 * 获取某一项目的某类型的反馈信息数量
	 * 
	 * @param p_id
	 *            项目id
	 * @param status
	 *            1为查询全部，0为只查询打开
	 * @param type
	 *            反馈信息类型，1为错误，2为需求，3为建议，4为其他
	 * @return
	 */
	int count_with_project_status_type(long p_id, int status, int type);

	/**
	 * 查询项目的某个里程碑的某状态的反馈信息数量
	 * 
	 * @param milestone_id
	 *            里程碑的id
	 * @param status
	 *            反馈信息状态,0为打开，1为关闭
	 * @return
	 */
	int count_milestone_status(long milestone_id, int status);

	/**
	 * 分页获取某里程碑的所有反馈信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @param milestone_id
	 *            里程碑的id
	 * @param params
	 *            标签的值，todo：待处理 done：已处理 all：全部 my_issue:我提出的待处理反馈信息
	 * @param login
	 *            用户的登录名（用户显示“我提出的”）
	 * @return
	 */
	PaginationResult<Issue> page_issue_milestone_all(
			PaginationCriteria criteria, long milestone_id, String label,
			String login);

	/**
	 * 分页获取某里程碑中指派给某人的反馈信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @param milestone_id
	 *            里程碑的id
	 * @param login
	 *            用户登录名
	 * @param params
	 *            标签的值，todo：待处理 done：已处理 all：全部 my_issue:我提出的待处理反馈信息
	 * @return
	 */
	PaginationResult<Issue> page_issue_milestone_login(
			PaginationCriteria criteria, long milestone_id, String login,
			String label);

	/**
	 * 获取某项目的最新十条待处理反馈信息
	 * 
	 * @param project_id
	 * @return
	 */
	List<Issue> get_issue_project_order(long project_id);

	/**
	 * 分页获取某一个项目的所有相关反馈信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @param project_id
	 *            项目的id
	 * @param login
	 *            用户登录名
	 * @param label
	 *            前台的标签，有todo，all，done，my_issue四个值
	 * @return
	 */
	PaginationResult<Issue> page_issue_project_all(PaginationCriteria criteria,
			long project_id, String login, String label);

	/**
	 * 分页获取某项目的相关反馈信息，根据用户身份选择性显示
	 * 
	 * @param criteria
	 *            分页信息
	 * @param project_id
	 *            项目的id
	 * @param login
	 *            用户登录名
	 * @param label
	 *            前台标签，有todo，all，done，my_issue四个值
	 * @return
	 */
	PaginationResult<Issue> page_issue_project_login(
			PaginationCriteria criteria, long project_id, String login,
			String label);

	/**
	 * 获取指派给该用户的所有fixed的issue信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @param login
	 *            用户登陆名
	 * @return
	 */
	PaginationResult<Issue> page_all_fixed_user(PaginationCriteria criteria,
			String login);

	/**
	 * 获取指派给该用户和该用户负责的所有项目的fixed的issue信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @param login
	 *            用户登录名
	 * @return
	 */
	PaginationResult<Issue> page_all_fixed_leader(PaginationCriteria criteria,
			String login);

	/**
	 * 获取所有的fixed的issue信息
	 * 
	 * @param criteria
	 *            分页信息
	 * @return
	 */
	PaginationResult<Issue> page_all_fixed(PaginationCriteria criteria);

	/**
	 * 根据milestone的id获取某状态的反馈信息数量
	 * 
	 * @param m_id
	 *            milestone的id
	 * @param status
	 *            反馈信息状态，1为关闭，不为1则为打开
	 * @return 反馈信息数量
	 */
	int count_with_milestone_status(long m_id, int status);

	/**
	 * 根据多重条件查询相关反馈信息
	 * 
	 * @param conditions
	 *            查询条件组成的dto
	 * @return 分页结果
	 */
	PaginationResult<Issue> page_issue_conditions(SelectCondition conditions);

	/**
	 * 分页获取某项目或者里程碑的当前用户提出的反馈信息
	 * 
	 * @param project_id
	 *            项目id
	 * @param milstone_id
	 *            里程碑id
	 * @param login
	 *            当前用户的登录名
	 * @param criteria
	 *            分页参数
	 * @return 分页反馈信息
	 */
	PaginationResult<Issue> page_issue_pro_mile(long project_id,
			long milestone_id, String login, PaginationCriteria criteria);
	
	/**
	 * 设置反馈信息所属某个里程碑
	 * @param issue_ids
	 *    反馈信息id组成的数组
	 * @param milestone
	 */
	int assign_to_milestone(long[]issue_ids,Milestone milestone);
	
	/**
	 * 获取反馈信息及其所处里程碑的信息
	 * @param issue_ids
	 * @return
	 */
	PaginationResult<IssueMilestone>list_page_issue_milestones(long[] issue_ids);
}
